package cn.iocoder.yudao.module.infrastructure.config.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.api.infrastructure.config.ConfigApiV2;
import cn.iocoder.yudao.module.api.infrastructure.config.dto.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.api.infrastructure.ConfigConstants.*;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 *  这里是文件说明
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/02/09
 */
@Tag(name = "管理后台 - 参数配置")
@RestController
@RequestMapping("/config")
@Validated
public class ConfigControllerV2 {
    @Resource
    private ConfigApiV2 configApiV2;

    @PostMapping("/pay/save")
    @Operation(summary = "保存财务中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<Boolean> savePayConfig(@Valid @RequestBody PayConfigRespDTO dto) {
        configApiV2.saveConfig(CONFIG_PAY, dto);
        return success(true);
    }

    @GetMapping("/pay/get")
    @Operation(summary = "获得财务中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<PayConfigRespDTO> getPayConfig() {
        PayConfigRespDTO config = configApiV2.getConfig(CONFIG_PAY, PayConfigRespDTO.class);
        return success(config);
    }

    @PostMapping("/member/save")
    @Operation(summary = "保存用户个人中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<Boolean> saveMemberConfig(@Valid @RequestBody MemberConfigRespDTO dto) {
        configApiV2.saveConfig(CONFIG_MEMBER, dto);
        return success(true);
    }

    @GetMapping("/member/get")
    @Operation(summary = "获得用户个人中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<MemberConfigRespDTO> getMemberConfig() {
        MemberConfigRespDTO config = configApiV2.getConfig(CONFIG_MEMBER, MemberConfigRespDTO.class);
        return success(config);
    }

    @PostMapping("/brokerage/save")
    @Operation(summary = "保存分佣推广中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<Boolean> saveBrokerageConfig(@Valid @RequestBody BrokerageConfigRespDTO dto) {
        configApiV2.saveConfig(CONFIG_BROKERAGE, dto);
        return success(true);
    }

    @GetMapping("/brokerage/get")
    @Operation(summary = "获得分佣推广中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<BrokerageConfigRespDTO> getBrokerageConfig() {
        BrokerageConfigRespDTO config = configApiV2.getConfig(CONFIG_BROKERAGE, BrokerageConfigRespDTO.class);
        return success(config);
    }

    @PostMapping("/mall/save")
    @Operation(summary = "保存商城配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<Boolean> saveProductConfig(@Valid @RequestBody MallConfigRespDTO dto) {
        configApiV2.saveConfig(CONFIG_MALL, dto);
        return success(true);
    }

    @GetMapping("/mall/get")
    @Operation(summary = "获得商城配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<MallConfigRespDTO> getProductConfig() {
        MallConfigRespDTO config = configApiV2.getConfig(CONFIG_MALL, MallConfigRespDTO.class);
        return success(config);
    }

    @PostMapping("/ad/save")
    @Operation(summary = "保存广告投放中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<Boolean> saveAdConfig(@Valid @RequestBody AdConfigRespDTO dto) {
        configApiV2.saveConfig(CONFIG_AD, dto);
        return success(true);
    }

    @GetMapping("/ad/get")
    @Operation(summary = "获得广告投放中心配置")
    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin')")
    public CommonResult<AdConfigRespDTO> getAdConfig() {
        AdConfigRespDTO config = configApiV2.getConfig(CONFIG_AD, AdConfigRespDTO.class);
        return success(config);
    }

}
